package com.bootcamp.javase.basic1;

import java.util.Random;
import java.util.Scanner;

/**
 * @program: BlockCode
 * @description: get the random number by giving hints of larger or smaller
 * @author: Keyu Li
 * @create: 2021-08-30 20:35
 **/

public class LargerOrSmaller {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Wanna to play? y/n");
        char yes = sc.nextLine().charAt(0);

        while (yes == 'y') {
            smallerOrBigger(sc);
            System.out.println("\nWanna to play? y/n");
            yes = sc.nextLine().charAt(0);
        }
    }

    private static void smallerOrBigger(Scanner sc) {
        Random rd = new Random();
        int ranValue = Math.abs(rd.nextInt(100));
        System.out.println("input a number within 100(-1 quit): ");
        int count = 0;
        int inputValue = Integer.parseInt(sc.nextLine());

        while (inputValue != -1){
            if (inputValue == ranValue){
                System.out.println("You Got It in "+count+" steps! Congratulations!");
                return;
            }else if (inputValue < ranValue )
                System.out.println("next bigger!");
            else {
                System.out.println("next smaller!");
            }
            count++;
            inputValue = Integer.parseInt(sc.nextLine());
        }
    }
}
